//
//  UIBarButtonItem+Zy.m
//
//  Created by zengbinsi_mac_mini on 15/11/4.
//  Copyright © 2015年 zengbinsi_mac_mini. All rights reserved.
//

#import "UIBarButtonItem+Zy.h"

@implementation UIBarButtonItem (Zy)

- (instancetype)initWithIcon:(NSString *)icon highlightedIcon:(NSString *)higlighted target:(id)target action:(SEL)action {
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    UIImage *image = [UIImage imageNamed:icon];
    [btn setBackgroundImage:image forState:UIControlStateNormal];
    [btn setBackgroundImage:[UIImage imageNamed:higlighted] forState:UIControlStateHighlighted];
    btn.imageEdgeInsets = UIEdgeInsetsMake(0, -13, 0, 0);
    btn.bounds = (CGRect){CGPointZero, image.size};
    [btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    return [self initWithCustomView:btn];
}

+ (instancetype)barButtonItemWithIcon:(NSString *)icon highlightedIcon:(NSString *)higlighted target:(id)target action:(SEL)action {
    return [[self alloc] initWithIcon:icon highlightedIcon:higlighted target:target action:action];
}

@end
